000100******************************************************************
000200*PROGRAM : Add Schedule
000300*AUTHOR  : Minh-Tuan Ta
000400******************************************************************
000500 IDENTIFICATION DIVISION.
000600 PROGRAM-ID. SCH-A.
000700 ENVIRONMENT DIVISION.
000800     SELECT IOFILE       ASSIGN TO "SCHEDMST.DAT"
000900                         ORGANIZATION    IS INDEXED
001000                         ACCESS          IS RANDOM
001100                         RECORD KEY      IS IO-SCHED-ID
001200                         FILE STATUS     IS WS-STAT.
001300
001400     SELECT INCRS        ASSIGN TO "CRSMST.DAT"
001500                         ORGANIZATION    IS INDEXED
001600                         ACCESS          IS DYNAMIC
001700                         RECORD KEY      IS CRS-ID
001800                         FILE STATUS     IS WS-STAT.
001900
002000     SELECT ININST       ASSIGN TO "INSTMST.DAT"
002100                         ORGANIZATION    IS INDEXED
002200                         ACCESS          IS DYNAMIC
002300                         RECORD KEY      IS INST-ID
                               ALTERNATE KEY   IS INST-NAME
                                               WITH DUPLICATES
002400                         FILE STATUS     IS WS-STAT.
002500
002600     SELECT INBLDG       ASSIGN TO "BLDGMST.DAT"
002700                         ORGANIZATION    IS INDEXED
002800                         ACCESS          IS DYNAMIC
002900                         RECORD KEY      IS BLDG-ID
003000                         FILE STATUS     IS WS-STAT.
003100
003200 DATA DIVISION.
003300 FILE SECTION.
003400 FD  IOFILE.
003500 01  IO-REC.
003600     05 IO-SCHED-ID.
003700         10 IO-TERM     PIC X(6).
003800         10 IO-CRN      PIC 9(4).
           05  IO-CRS-ID       PIC X(8).
           05  IO-BLDG-ID      PIC X(11).
           05  IO-INST-ID      PIC 9(3).
           05  IO-TIME         PIC X(15).
004000     05  IO-ACTIVE      PIC X.
004100
004200 FD  INCRS.
004300 01  CRS-REC.
004400     05  CRS-ID              PIC X(8).
004500     05  CRS-NAME            PIC X(34).
004600     05  CRS-HR              PIC 99.
004700     05  CRS-ACTIVE          PIC X.
004800
004900 FD  ININST.
005000 01  INST-REC.
005100     05  INST-ID             PIC 9(3).
005200     05  INST-NAME           PIC X(20).
005300     05  INST-ACTIVE         PIC X.
005400
005500 FD  INBLDG.
005600 01  BLDG-REC.
005700     05  BLDG-ID             PIC X(11).
005800     05  BLDG-CAPACITY       PIC 9(3).
005900     05  BLDG-ACTIVE         PIC X.
006000
006200 WORKING-STORAGE SECTION.
006300 01  WS-STAT             PIC XX.
006400 01  WS-EOF              PIC X VALUE 'N'.
006500 01  WS-SCHEDKEY.
006600     05  WS-TERM             PIC 9(6).
006700     05  WS-CRN              PIC 9(4).
006800
006900 01  WS-CRS-ID           PIC  X(8).
007000 01  WS-BLDG-ID          PIC  X(11).
007100 01  WS-INST-ID          PIC  9(3).
007200
007300 01  WS-ACTIVE           PIC X.
007400 01  WS-DATE.
007500     03  WS-YEAR         PIC 99.
007600     03  WS-MONTH        PIC 99.
007700     03  WS-DAY          PIC 99.
007800 01  WS-ERR              PIC X VALUE 'N'.
007900 01  WS-CONT             PIC X VALUE 'Y'.
       01  WS-ADD              PIC X.
008000
008100 SCREEN SECTION.
008200 01  INPUT-SCRN.
008300         05  BLANK SCREEN.
008400         05  LINE 1  COL 01  VALUE "INQUIRY SCHEDULE".
008500         05          COL 73  PIC 9(2) FROM WS-MONTH.
008600         05          COL 75  VALUE "/".
008700         05          COL 76  PIC 9(2) FROM WS-DAY.
008800         05          COL 78  VALUE "/".
008900         05          COL 79  PIC 9(2) FROM WS-YEAR.
009000         05  LINE 2  COL 37  VALUE "INQUIRY".
009100         05  INPUT-TERM-SCRN.
009200             10  LINE 4  COL 20  VALUE "TERM".
009300             10          COL 40  PIC X(6) TO IO-TERM.
009400             10          COL 40  PIC X(6) FROM IO-TERM.
009500         05  INPUT-CRN-SCRN.
009600             10  LINE 5  COL 20  VALUE "CRN".
009700             10          COL 40  PIC 9(4) TO IO-CRN.
009800             10          COL 40  PIC 9(4) FROM IO-CRN.
               05 LINE 6  COL 20  VALUE "COURSE ID".
010100         05         COL 40  PIC X(8) FROM IO-CRS-ID.

010200         05  LINE 7  COL 20  VALUE "COURSE NAME".
010300         05          COL 40  PIC X(34) FROM CRS-NAME.
010400         05  LINE 8  COL 20  VALUE "CREDIT HR".
010500         05          COL 40  PIC 99  FROM CRS-HR.
               05  LINE 9  COL 20  VALUE "BUILDING ID".
               05          COL 40  PIC X(11) FROM IO-BLDG-ID.
010800         05  LINE 10 COL 20  VALUE "CAPACITY".
010900         05          COL 40  PIC 9(3) FROM BLDG-CAPACITY.
               05  LINE 11 COL 20 VALUE "INSTRUCTOR ID".
               05          COL 40  PIC 9(3)    FROM IO-INST-ID.
011000         05  LINE 12 COL 20  VALUE "INSTRUCTOR".
011100         05          COL 40  PIC X(20) FROM INST-NAME.
011200         05  LINE 13 COL 20  VALUE "TIME".
               05          COL 40  PIC X(15)   FROM IO-TIME.
011900         05  LINE 14 COL 20  VALUE "ACTIVE(Y/N)?".
012000         05          COL 40  PIC X   FROM IO-ACTIVE.
012100
012200         05  LINE 16 COL 34  VALUE "(ENTER XXX TO TERM TO EXIT)".
               05  INPUT-CONT-SCRN.
                   10  LINE 18 COL 34 VALUE "CONTINUE(Y/N)?".
                   10          COL 32  PIC X TO WS-CONT AUTO.
012300
012400 01  ERROR-SCRN.
012500     03  BLANK SCREEN.
012600     03  LINE 12 COL 32 VALUE "ERROR".
012700     03  LINE 14 COL 32 VALUE "FILE STATUS:".
012800     03          COL 46 PIC XX FROM WS-STAT.
012900     03  LINE 16 COL 32 VALUE "CONTINUE(Y/N)?".
013000     03          COL 47 PIC X TO WS-CONT AUTO.
013700
013800
013900 PROCEDURE DIVISION.
014000 100-MAIN.
014100     ACCEPT WS-DATE FROM DATE
014200     OPEN    I-O IOFILE
014300
014400             INPUT ININST
014500             INPUT INCRS
014600             INPUT INBLDG
014700
           MOVE SPACES TO IO-TERM
           MOVE ZEROS TO IO-CRN
           MOVE SPACES TO IO-CRS-ID
           MOVE SPACES TO IO-BLDG-ID
           MOVE ZEROS TO IO-INST-ID
           MOVE SPACES TO IO-TIME
           MOVE SPACES TO CRS-ID
           MOVE SPACES TO CRS-NAME
           MOVE ZEROS TO CRS-HR
           MOVE SPACES TO BLDG-ID
           MOVE ZEROS TO BLDG-CAPACITY
           MOVE SPACES TO INST-NAME
           MOVE SPACES TO IO-ACTIVE
           MOVE SPACES TO WS-CONT

015900
016000     DISPLAY INPUT-SCRN
016100     ACCEPT INPUT-TERM-SCRN
016200
016300     PERFORM UNTIL IO-TERM = 'XXX' OR WS-CONT = 'N'
016400
016500         ACCEPT INPUT-CRN-SCRN

               MOVE 'N' TO WS-ERR

               READ IOFILE
                   INVALID KEY MOVE 'Y' TO WS-ERR
               END-READ

               IF NOT WS-ERR = 'Y'
                   MOVE IO-CRS-ID TO CRS-ID

                   START INCRS KEY = CRS-ID
                   END-START

                   READ INCRS NEXT RECORD
                   END-READ

                   MOVE IO-BLDG-ID TO BLDG-ID

                   START INBLDG KEY = BLDG-ID
                   END-START

                   READ INBLDG NEXT RECORD
                   END-READ

                   MOVE IO-INST-ID TO INST-ID

                   START ININST KEY = INST-ID
                   END-START

                   READ ININST NEXT RECORD
                   END-READ

                   DISPLAY INPUT-SCRN
                   ACCEPT INPUT-CONT-SCRN
               ELSE
                   DISPLAY ERROR-SCRN
                   ACCEPT ERROR-SCRN
               END-IF


               IF NOT WS-CONT = 'N'
                   MOVE SPACES TO IO-TERM
                   MOVE ZEROS TO IO-CRN
                   MOVE SPACES TO IO-CRS-ID
                   MOVE SPACES TO IO-BLDG-ID
                   MOVE ZEROS TO IO-INST-ID
                   MOVE SPACES TO IO-TIME
                   MOVE SPACES TO CRS-ID
                   MOVE SPACES TO CRS-NAME
                   MOVE ZEROS TO CRS-HR
                   MOVE SPACES TO BLDG-ID
                   MOVE ZEROS TO BLDG-CAPACITY
                   MOVE SPACES TO INST-NAME
                   MOVE SPACES TO IO-ACTIVE

                   DISPLAY INPUT-SCRN
                   ACCEPT INPUT-TERM-SCRN
               END-IF

           END-PERFORM

       CLOSE IOFILE

       CLOSE ININST
       CLOSE INCRS
       CLOSE INBLDG

       EXIT PROGRAM.

